import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { svgBuilder } from './src/utils/svg/svgBuilder'

// 自动导入vue中hook reactive ref等
import AutoImport from "unplugin-auto-import/vite"
import { resolve } from "path"
//自动导入ui-组件 比如说ant-design-vue  element-plus等
import Components from 'unplugin-vue-components/vite'
import IconsResolver from "unplugin-icons/resolver";
//Ant
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
//element
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
// import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
export default defineConfig({
  base: "./", 
  plugins: [
    vue(),
    Components({//自定义的模块
      dirs: ['src/components'],
      extensions: ['vue', 'ts'],
      resolvers: [AntDesignVueResolver(), ElementPlusResolver()],//所自动导入的element和Ant
    }),
    AutoImport({ // 插件进行自动导入相关的依赖库
      include: [
        /\.[tj]sx?$/,
        /\.vue$/,
        /\.vue\?vue/,
      ],
      dts: true,
      imports: ['vue',
        'vue-router',
        'pinia',
        {
          // '@vueuse/core': [
          //   // named imports
          //   'useMouse', // import { useMouse } from '@vueuse/core',
          //   // alias
          //   ['useFetch', 'useMyFetch'], // import { useFetch as useMyFetch } from '@vueuse/core',
          // ],
          'axios': [
            // default imports
            ['default', 'axios'], // import { default as axios } from 'axios',
          ],
          'echarts': [
            // default imports
            'echarts', // import { default as echarts } from 'echarts',
          ],
        },
      ],
      // eslint报错解决
      eslintrc: {
        enabled: true, // Default `false`
        filepath: './.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
        globalsPropValue: true, // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
      },
      // element plus按需导入
      resolvers: [
        //自动导入element plus相关函数
        ElementPlusResolver(),
        // Auto import icon components
        // 自动导入图标组件
        IconsResolver({
          prefix: "Icon",
        }),
      ]
    }),
    svgBuilder('./src/assets/icons/svg/')
  ],
  resolve: {
    alias: [
      {
        find: '@',
        replacement: resolve(__dirname, './src'),
      }
    ]
  },
  server:{  //中转服务器
    proxy:{ //通过代理实现跨域
      '/api':{
        // target:'http://36.140.31.145:31011', //替换的服务器地址 
        target:'http://172.18.38.19:8001', //替换的服务器地址 
        changeOrigin:true,//开启代理，允许跨域
        // 重写路径 --> 作用与vue配置pathRewrite作用相同
        rewrite: (path) => path.replace(/^\/api/, "") 
      }
    },
    host: '0.0.0.0', //ip地址
    port:5000,
    open:true
  }
})
